package com.zzj.controller;


import com.github.pagehelper.PageInfo;
import com.zzj.bean.TabFlower;
import com.zzj.service.TabFlowerService;
import com.zzj.service.TabSupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * InnoDB free: 8192 kB 前端控制器
 * </p>
 *
 * @author 花
 * @since 2022-03-04
 */
@Api
@CrossOrigin
@RestController
@RequestMapping("/flower")
public class TabFlowerController {
//    花的service层
    @Autowired
    private TabFlowerService tabFlowerService;
//    供货记录 service层
    @Resource
    private TabSupplierService tabSupplierService;

    @GetMapping("findAllFlower")
    @ApiOperation(value = "查询所有上架的花")
    public PageInfo<TabFlower> findAll(@RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "6") Integer pageSize){
        return tabFlowerService.findAll(pageNum,pageSize);
    }

    @GetMapping("getFlower")
    @ApiOperation("获取花名与id")
    public List<TabFlower> getFlower(){
        return tabFlowerService.list();
    }

    @ApiOperation("修改花商品的信息")
    @PutMapping("updateFlower")
    public boolean updateInfo(@RequestBody TabFlower tabFlower){

        return tabFlowerService.updateById(tabFlower);
    }

    @ApiOperation("通过id获取该商品")
    @GetMapping("getById/{fid}")
    public TabFlower getById(@PathVariable("fid") String fid){
        return tabFlowerService.findOneById(fid);
    }


    @DeleteMapping("del/{id}")
    @ApiOperation("下架某个花")
    public boolean del(@PathVariable("id") Integer fid){
        return tabFlowerService.removeById(fid);
    }

    @PostMapping("fuzzyQuery")
    @ApiOperation("模糊查询")
    public PageInfo<TabFlower> fuzzyQuery(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "6") Integer pageSize,
                              @RequestBody Map<String,String> map){
        System.out.println(map.get("key"));
        System.out.println(map.get("value"));
        return tabFlowerService.getFlowerByLike(pageNum,pageSize,map.get("key"),map.get("value"));
    }

}

